package com.lingyu.jsjx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lingyu.jsjx.domain.TeacherTenet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.lingyu.jsjx.domain.ScientificResearch;
import com.lingyu.jsjx.service.IScientificResearchService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 科研管理
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/scientificResearch")
public class ScientificResearchController extends BaseController
{
    @Autowired
    private IScientificResearchService scientificResearchService;

    /**
     * 查询科研管理列表
     */
    @RequiresPermissions("jsjx:scientificResearch:list")
    @GetMapping("/list")
    public TableDataInfo list(ScientificResearch scientificResearch)
    {
        startPage();
        List<ScientificResearch> list = scientificResearchService.selectScientificResearchList(scientificResearch);
        return getDataTable(list);
    }

    /**
     * 导出科研管理列表
     */
    @RequiresPermissions("jsjx:scientificResearch:export")
    @Log(title = "科研管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScientificResearch scientificResearch)
    {
        List<ScientificResearch> list = scientificResearchService.selectScientificResearchList(scientificResearch);
        ExcelUtil<ScientificResearch> util = new ExcelUtil<ScientificResearch>(ScientificResearch.class);
        util.exportExcel(response, list, "科研管理数据");
    }

    /**
     * 获取科研管理详细信息
     */
    @RequiresPermissions("jsjx:scientificResearch:query")
    @GetMapping(value = "/{researchId}")
    public AjaxResult getInfo(@PathVariable("researchId") Long researchId)
    {
        return success(scientificResearchService.selectScientificResearchByResearchId(researchId));
    }

    /**
     * 新增科研管理
     */
    @RequiresPermissions("jsjx:scientificResearch:add")
    @Log(title = "科研管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScientificResearch scientificResearch)
    {
        return toAjax(scientificResearchService.insertScientificResearch(scientificResearch));
    }

    /**
     * 修改科研管理
     */
    @RequiresPermissions("jsjx:scientificResearch:edit")
    @Log(title = "科研管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScientificResearch scientificResearch)
    {
        return toAjax(scientificResearchService.updateScientificResearch(scientificResearch));
    }

    /**
     * 删除科研管理
     */
    @RequiresPermissions("jsjx:scientificResearch:remove")
    @Log(title = "科研管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{researchIds}")
    public AjaxResult remove(@PathVariable Long[] researchIds)
    {
        return toAjax(scientificResearchService.deleteScientificResearchByResearchIds(researchIds));
    }

    /**
     * 科研经费统计
     * @return
     */
    @GetMapping(value = "/queryCountBudgetStatistic")
    public AjaxResult queryCountBudgetStatistic()
    {
        return success(scientificResearchService.selectCountBudgetStatistic());
    }

    @GetMapping(value = "/queryResearchTypeCount")
    public AjaxResult queryResearchTypeCount(){
        return success(scientificResearchService.selectResearchTypeCount());
    }


    @Log(title = "科研管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<ScientificResearch> util = new ExcelUtil<>(ScientificResearch.class);
        List<ScientificResearch> scientificResearchList = util.importExcel(file.getInputStream());
        String message = scientificResearchService.importScientificResearch(scientificResearchList, false);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<ScientificResearch> util = new ExcelUtil<>(ScientificResearch.class);
        util.importTemplateExcel(response, "教学心旨数据");
    }
}
